package com.earthquake.monitor_system.utils.urlData;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.earthquake.monitor_system.dao.IconClassifyDao;
import com.earthquake.monitor_system.dao.IconDao;
import com.earthquake.monitor_system.domain.IconClassifyDomain;
import com.earthquake.monitor_system.domain.IconDomain;
import com.earthquake.monitor_system.service.impl.SeismicInformationImpl;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.net.URL;
@Controller
public class Icon {
    @Autowired
    private SeismicInformationImpl seismicInformation;
    @Resource
    private IconClassifyDao iconClassifyDao;
    @Resource
    private IconDao iconDao;
    public static Icon icon;
    @PostConstruct
    public void init() {
        icon = this;
        icon.seismicInformation = this.seismicInformation;
        icon.iconDao=this.iconDao;
        icon.iconClassifyDao = this.iconClassifyDao;
    }
    public  void getdata() throws Exception {
        String str = "https://element-plus.gitee.io/zh-CN/component/icon.html";
        //方法二：parse解析URL
        Document document = Jsoup.parse(new URL(str), 30000);
        Elements element = document.getElementsByClass("demo-icon-item");//网页节点
        for (int i = 0; i < element.size(); i++) {
            Element element1 = element.get(i);
            String classify = element1.select(".demo-icon-title").text();
            Boolean Binset = icon.iconClassifyDao.inset(classify);
            if(!Binset){
                return;
            }
            IconClassifyDomain list = icon.iconClassifyDao.getOne(classify);
            // 分类的id
            Integer classifyId = list.getId();

            Elements select = element1.select(".demo-icon-list");
            String iconName = select.select(".icon-name").text();
            String[] iconNameList = iconName.split(" ");
            for (int item = 0; item < iconNameList.length; item++) {
                icon.iconDao.inset(iconNameList[item],classifyId);
            }
        }
    }
}
